package com.ncdnapp.core.entity;

import com.ncdnapp.core.entity.enums.ResultEnum;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

import java.io.Serializable;

@Data
@Accessors(chain = true)
@EqualsAndHashCode
public class Response<T> implements Serializable {
    public boolean success;
    private String code;
    private String msg;
    private T data;

    public static Response<Object> success() {
        return create().setSuccess(true).setCode(ResultEnum.SUCCESS.getCode()).setMsg(ResultEnum.SUCCESS.getMsg());
    }

    public static Response<Object> success(Object data) {
        return success().setData(data);
    }

    public static Response<Object> fail(String code, String msg) {
        return create().setSuccess(false).setCode(code).setMsg(msg);
    }

    public static Response<Object> fail(String code, String msg, Object data) {
        return create().setSuccess(false).setCode(code).setMsg(msg).setData(data);
    }

    public static Response<Object> create() {
        return new Response<Object>();
    }
}
